package com.business.system.official.toursism.websitegoods.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.system.official.toursism.websitegoods.entity.WebsiteGoods;
import com.business.system.official.toursism.websitegoods.manager.WebsiteGoodsManager;
import com.business.system.official.toursism.websitegoods.mapper.WebsiteGoodsMapper;
import com.business.system.official.toursism.websitegoods.vo.WebsiteGoodsBriefListVO;
import com.business.system.official.toursism.websitegoods.vo.WebsiteGoodsBriefVO;
import com.business.system.official.toursism.websitegoods.vo.WebsiteGoodsDetailListVO;
import com.business.system.official.toursism.websitegoods.vo.WebsiteGoodsDetailVO;
import com.business.system.official.toursism.websitegoods.vo.data.WebsiteGoodsBriefData;
import com.business.system.official.toursism.websitegoods.vo.data.WebsiteGoodsDetailData;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedSystemManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 商品
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Transactional(rollbackFor = ManagerException.class)
@Service("websiteGoodsManager")
public class WebsiteGoodsManagerImpl extends SeedSystemManagerImpl<WebsiteGoodsMapper, WebsiteGoods> implements WebsiteGoodsManager {

    /**
     * 根据id获取详情VO data
     *
     * @param websiteGoodsId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailData convertDetailData(String websiteGoodsId) throws ManagerException {
        WebsiteGoods websiteGoods = this.getById(websiteGoodsId);
        return this.convertDetailData(websiteGoods);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoods model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailData convertDetailData(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsDetailData websiteGoodsDetailData = new WebsiteGoodsDetailData();
        try {
            BeanUtils.copyProperties(websiteGoods, websiteGoodsDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteGoods);
        }
        return websiteGoodsDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteGoodsId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailVO getDetailVO(String websiteGoodsId) throws ManagerException {
        WebsiteGoodsDetailData websiteGoodsDetailData = this.convertDetailData(websiteGoodsId);
        return new WebsiteGoodsDetailVO(websiteGoodsDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteGoods 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailVO getDetailVO(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsDetailData websiteGoodsDetailData = this.convertDetailData(websiteGoods);
        return new WebsiteGoodsDetailVO(websiteGoodsDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsDetailData> getConvertDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteGoodsList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsDetailData> listConvertDetailData(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteGoodsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoodsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsDetailData> listConvertDetailData(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        List<WebsiteGoodsDetailData> websiteGoodsDetailDataList = new ArrayList<>();
        for (WebsiteGoods websiteGoods : websiteGoodsList) {
            websiteGoodsDetailDataList.add(this.convertDetailData(websiteGoods));
        }
        return websiteGoodsDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailListVO getDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteGoodsDetailListVO(this.getConvertDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailListVO getDetailListVO(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        return new WebsiteGoodsDetailListVO(this.listConvertDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteGoodsList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsDetailListVO getDetailListVO(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        return new WebsiteGoodsDetailListVO(this.listConvertDetailData(websiteGoodsList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteGoodsId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefData convertBriefData(String websiteGoodsId) throws ManagerException {
        WebsiteGoods websiteGoods = this.getById(websiteGoodsId);
        return this.convertBriefData(websiteGoods);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoods model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefData convertBriefData(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsBriefData websiteGoodsBriefData = new WebsiteGoodsBriefData();
        try {
            BeanUtils.copyProperties(websiteGoods, websiteGoodsBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteGoods);
        }
        return websiteGoodsBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteGoodsId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefVO getBriefVO(String websiteGoodsId) throws ManagerException {
        WebsiteGoodsBriefData websiteGoodsBriefData = this.convertBriefData(websiteGoodsId);
        return new WebsiteGoodsBriefVO(websiteGoodsBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteGoods 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefVO getBriefVO(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsBriefData websiteGoodsBriefData = this.convertBriefData(websiteGoods);
        return new WebsiteGoodsBriefVO(websiteGoodsBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsBriefData> listConvertBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteGoodsList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsBriefData> listConvertBriefData(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteGoodsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoodsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsBriefData> listConvertBriefData(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        List<WebsiteGoodsBriefData> websiteGoodsBriefDataList = new ArrayList<>();
        for (WebsiteGoods websiteGoods : websiteGoodsList) {
            websiteGoodsBriefDataList.add(this.convertBriefData(websiteGoods));
        }
        return websiteGoodsBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefListVO getBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return new WebsiteGoodsBriefListVO(this.listConvertBriefData(websiteGoodsList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefListVO getBriefListVO(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return new WebsiteGoodsBriefListVO(this.listConvertBriefData(websiteGoodsList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteGoodsList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsBriefListVO getBriefListVO(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        return new WebsiteGoodsBriefListVO(this.listConvertBriefData(websiteGoodsList));
    }
}
